#!/bin/bash

echo "正在修复VSCode IntelliSense问题..."

# 1. 清除VSCode C++扩展缓存
echo "清除VSCode缓存..."
rm -rf ~/.vscode/extensions/ms-vscode.cpptools-*/bin/.browse.VC.db*
rm -rf ~/.vscode/extensions/ms-vscode.cpptools-*/bin/ipch

# 2. 重新生成compile_commands.json
echo "重新生成compile_commands.json..."
cat > compile_commands.json << 'EOF'
[
  {
    "directory": "/Users/sea/Documents/study2/cpp_box/cpp_grpc",
    "command": "clang++ -std=c++17 -I/opt/homebrew/Cellar/grpc/1.74.0/include -I/opt/homebrew/Cellar/abseil/20240722.1/include -I/opt/homebrew/Cellar/c-ares/1.34.5/include -I/opt/homebrew/Cellar/openssl@3/3.5.1/include -I/opt/homebrew/Cellar/re2/20250805/include -I/opt/homebrew/Cellar/protobuf/29.3/include -I./include -I./build -c src/server.cpp -o build/server.o",
    "file": "/Users/sea/Documents/study2/cpp_box/cpp_grpc/src/server.cpp"
  },
  {
    "directory": "/Users/sea/Documents/study2/cpp_box/cpp_grpc",
    "command": "clang++ -std=c++17 -I/opt/homebrew/Cellar/grpc/1.74.0/include -I/opt/homebrew/Cellar/abseil/20240722.1/include -I/opt/homebrew/Cellar/c-ares/1.34.5/include -I/opt/homebrew/Cellar/openssl@3/3.5.1/include -I/opt/homebrew/Cellar/re2/20250805/include -I/opt/homebrew/Cellar/protobuf/29.3/include -I./include -I./build -c src/client.cpp -o build/client.o",
    "file": "/Users/sea/Documents/study2/cpp_box/cpp_grpc/src/client.cpp"
  }
]
EOF

echo "修复完成！"
echo ""
echo "请在VSCode中执行以下步骤："
echo "1. 按 Cmd+Shift+P"
echo "2. 输入 'Developer: Reload Window' 并执行"
echo "3. 按 Cmd+Shift+P"
echo "4. 输入 'C/C++: Reset IntelliSense Database' 并执行"
echo "5. 按 Cmd+Shift+P"
echo "6. 输入 'C/C++: Rescan Workspace' 并执行"
echo ""
echo "如果问题仍然存在，请重启VSCode。"